package com.qf.service;

import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("service1")
public class UserServiceImpl implements UserService {
    //需要被注入的用户dao全局对象
    @Autowired
    private UserMapper userMapper;

    //从jdbc.properties文件中根据key拿到value的值
    @Value("${jdbc.url}")
    private String url;

    @Value("${jdbc.username}")
    private String username;

    public UserMapper getUserMapper() {
        return userMapper;
    }
    //进行set注入
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    public List<User> findAll() {
        System.out.println("url="+url);
        System.out.println("username="+username);
        //直接用注入的UserMapper对象
        List<User> list = userMapper.findUserAll();
        return list;
    }

    public void updateUser(User user) {

        userMapper.updateUser(user);

        //演示在拥有事务的操作中，如果出现异常，是否会回滚
        int i = 1/0;
    }
}
